<template>
	<view class="content">
		<van-nav-bar
		  title="流通记录"
		  left-text="返回"
		  left-arrow
		  @click-left="onClickLeft"
		/>
		<van-list
		  :finished="this.finished"
		  finished-text="没有更多了"
		  @load="getCodeCirculate()"
		>
			<van-cell center v-for="item in list" :value="status_text[item.option_type]"  >
			  <!-- 使用 title 插槽来自定义标题 -->
			  <template #title>
				<view>公司：{{item.factory}}</view>
				<view>员工：{{item.realname}}</view>
				<view>地址：{{item.province}}  {{item.city}}  {{item.factoryAddress}}</view>
				<view> 时间：{{timeStr(item.create_time)}}</view>
			  </template>
			</van-cell>
		</van-list>
	</view>
</template>

<script>
import axios from 'axios';
import { showToast } from 'vant';
	export default {
		data() {
			return {
				tag: '',
				code: '',
				list: [],
				status_color: ['primary','success','danger'],
				status_text: ['出库','入库','激活'],
				loading: false,
				finished: false,
		
			}
		},
		
		onLoad(opt) {
			this.code = opt.code
			this.getCodeCirculate()
		},
		
		methods: {
			onClickLeft() {
			     uni.navigateBack({
			       delta: 1 // 返回的页面数，1表示返回上一页，2表示返回上两页，以此类推
			     })
			   },
			navigateToItem(productCode){
				uni.navigateTo({
					url: '/pages/productDetail/productDetail?productCode=' + productCode
				})
			},
			timeStr(timestamp) {
				timestamp = parseInt(timestamp)
					if (timestamp < 2000000000) timestamp = timestamp * 1000
						console.log(timestamp)
							var date = new Date(timestamp);
							const year = date.getFullYear();
							const month = ("0" + (date.getMonth() + 1)).slice(-2);
							const day = ("0" + date.getDate()).slice(-2);
							const hour = ("0" + date.getHours()).slice(-2);
							const minute = ("0" + date.getMinutes()).slice(-2);
							const second = ("0" + date.getSeconds()).slice(-2);
							return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
			},
			getCodeCirculate(){
				axios({
				  method: 'post',
				  url: 'https://service.wulings.com/api/code/getCodeCirculate',
				  data: {
				    "code": this.code,
				  },
				  headers: {
				    'Content-Type': 'application/x-www-form-urlencoded'
				  }
				})
				.then(res => {
					console.log('getCodeCirculate',res.data);
					this.list = res.data
					
				})
				.catch(err => {
				  // 请求失败时的回调函数
				  showFailToast('获取失败');
				});
				
				
			}
		}
	}
</script>

<style>
	.vantCard {
		margin-top: 25px;
		margin-bottom: 50px;
	}

</style>
